<template>
  <div>
    <Card>
      <div class="base-info-item">
        <h4>活动详情</h4>
      </div>
      <Table border :columns="columnsHead" :data="formHead"></Table>
      <div class="base-info-item">
        <h4>商品信息</h4>
      </div>
      <Table
        border
        :columns="columns"
        :data="form.promotionGoodsList"
      ></Table>
    </Card>
  </div>
</template>
  
  <script>
import {
  buyActivityList,
  upBuyActivity,
  buyActivityDetail
} from "@/api/promotion";
export default {
  data() {
    return {
      id: this.$route.query.id, // 活动id
      form: [],
      formHead: [],
      columnsHead: [
        {
          title: "活动名称",
          key: "promotionName",
          minWidth: 120
        },
        {
          title: "开始时间",
          key: "startTime",
          minWidth: 60
        },
        {
          title: "结束时间",
          key: "endTime",
          minWidth: 60
        },
        {
          title: "活动状态",
          key: "promotionStatus",
          width: 100,
          render: (h, params) => {
            let text = "未知",
              color = "default";
            if (params.row.promotionStatus == "NEW") {
              text = "未开始";
              color = "default";
            } else if (params.row.promotionStatus == "START") {
              text = "已开始";
              color = "green";
            } else if (params.row.promotionStatus == "END") {
              text = "已结束";
              color = "blue";
            } else if (params.row.promotionStatus == "CLOSE") {
              text = "已关闭";
              color = "red";
            }
            return h("div", [
              h(
                "Tag",
                {
                  props: {
                    color: color
                  }
                },
                text
              )
            ]);
          }
        }
      ],
      columns: [
        {
          title: "商品名称",
          key: "goodsName",
          minWidth: 120
        },
        {
          title: "商品价格",
          key: "price",
          minWidth: 40
        },
        {
          title: "库存",
          key: "quantity",
          minWidth: 40
        }
      ]
    };
  },
  async mounted() {
    this.getDetail();
  },
  methods: {
    getDetail() {
      // 获取活动详情
      buyActivityDetail(this.id).then(res => {
        if (res.success) {
          let headObj = {
            promotionName: res.result.promotionName,
            startTime: res.result.startTime,
            endTime: res.result.endTime,
            promotionStatus: res.result.promotionStatus
          };
          this.formHead.push(headObj);
          let data = res.result;
          if (data.scopeType === "ALL") {
            data.promotionGoodsList = [];
          }
          if (data.fullMinusFlag) {
            data.discountType = "fullMinusFlag";
            delete data.fullMinusFlag;
          } else {
            data.discountType = "fullRateFlag";
            delete data.fullRateFlag;
          }
          data.rangeTime = [];
          data.rangeTime.push(new Date(data.startTime), new Date(data.endTime));
          this.form = data;
        }
      });
    },
  
  }
};
</script>
  
  <style lang="scss" scoped>
h4 {
  margin-bottom: 10px;
  border-left: 2px solid #ff0000;
  padding: 0 10px;
  background-color: #f8f8f8;
  font-weight: bold;
  color: #333;
  font-size: 14px;
  line-height: 40px;
  text-align: left;
}

.ivu-form-item {
  margin-bottom: 24px !important;
}
</style>
  